const express = require('express');
const router = express.Router();
const LocationController = require('../controllers/locationController');

/**
 * @swagger
 * tags:
 *   name: Locations
 *   description: 货位管理
 */

/**
 * @swagger
 * /api/locations:
 *   get:
 *     summary: 获取所有货位
 *     tags: [Locations]
 *     responses:
 *       200:
 *         description: 成功获取货位列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   type: array
 *                   items:
 *                     $ref: '#/components/schemas/Location'
 *       500:
 *         description: 服务器错误
 */
router.get('/', LocationController.getAllLocations);

/**
 * @swagger
 * /api/locations/query:
 *   get:
 *     summary: 根据查询条件获取货位
 *     tags: [Locations]
 *     parameters:
 *       - in: query
 *         name: locationCode
 *         schema:
 *           type: string
 *         description: 货位编码
 *       - in: query
 *         name: aisle
 *         schema:
 *           type: string
 *         description: 巷道
 *       - in: query
 *         name: row
 *         schema:
 *           type: string
 *         description: 排
 *       - in: query
 *         name: column
 *         schema:
 *           type: string
 *         description: 列
 *       - in: query
 *         name: level
 *         schema:
 *           type: string
 *         description: 层
 *       - in: query
 *         name: status
 *         schema:
 *           type: string
 *         description: 状态(enabled/disabled)
 *     responses:
 *       200:
 *         description: 成功获取货位列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   type: array
 *                   items:
 *                     $ref: '#/components/schemas/Location'
 *       500:
 *         description: 服务器错误
 */
router.get('/query', LocationController.getLocationsByQuery);

/**
 * @swagger
 * /api/locations/config:
 *   get:
 *     summary: 获取仓库配置信息
 *     tags: [Locations]
 *     responses:
 *       200:
 *         description: 成功获取仓库配置信息
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   type: object
 *                   properties:
 *                     aisleCount:
 *                       type: integer
 *                     rowCount:
 *                       type: integer
 *                     columnCount:
 *                       type: integer
 *                     levelCount:
 *                       type: integer
 *       500:
 *         description: 服务器错误
 */
router.get('/config', LocationController.getWarehouseConfig);

/**
 * @swagger
 * /api/locations/{id}:
 *   get:
 *     summary: 根据ID获取货位
 *     tags: [Locations]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 货位ID
 *     responses:
 *       200:
 *         description: 成功获取货位
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   $ref: '#/components/schemas/Location'
 *       404:
 *         description: 货位未找到
 *       500:
 *         description: 服务器错误
 */
router.get('/:id', LocationController.getLocationById);

/**
 * @swagger
 * /api/locations/code/{code}:
 *   get:
 *     summary: 根据货位编码获取货位
 *     tags: [Locations]
 *     parameters:
 *       - in: path
 *         name: code
 *         required: true
 *         schema:
 *           type: string
 *         description: 货位编码
 *     responses:
 *       200:
 *         description: 成功获取货位
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   $ref: '#/components/schemas/Location'
 *       404:
 *         description: 货位未找到
 *       500:
 *         description: 服务器错误
 */
router.get('/code/:code', LocationController.getLocationByCode);

/**
 * @swagger
 * /api/locations:
 *   post:
 *     summary: 创建新货位
 *     tags: [Locations]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - locationCode
 *               - aisle
 *               - row
 *               - column
 *               - level
 *             properties:
 *               locationCode:
 *                 type: string
 *                 description: 货位编码
 *               aisle:
 *                 type: string
 *                 description: 巷道
 *               row:
 *                 type: string
 *                 description: 排
 *               column:
 *                 type: string
 *                 description: 列
 *               level:
 *                 type: string
 *                 description: 层
 *               status:
 *                 type: string
 *                 description: 状态(enabled/disabled)
 *     responses:
 *       201:
 *         description: 货位创建成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *                 data:
 *                   $ref: '#/components/schemas/Location'
 *       400:
 *         description: 请求参数错误
 *       500:
 *         description: 服务器错误
 */
router.post('/', LocationController.createLocation);

/**
 * @swagger
 * /api/locations/{id}/status:
 *   put:
 *     summary: 更新货位状态
 *     tags: [Locations]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 货位ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - status
 *             properties:
 *               status:
 *                 type: string
 *                 description: 状态(enabled/disabled)
 *     responses:
 *       200:
 *         description: 货位状态更新成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *       400:
 *         description: 请求参数错误
 *       404:
 *         description: 货位未找到
 *       500:
 *         description: 服务器错误
 */
router.put('/:id/status', LocationController.updateLocationStatus);

/**
 * @swagger
 * /api/locations/status/batch:
 *   put:
 *     summary: 批量更新货位状态
 *     tags: [Locations]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - ids
 *               - status
 *             properties:
 *               ids:
 *                 type: array
 *                 items:
 *                   type: integer
 *                 description: 货位ID数组
 *               status:
 *                 type: string
 *                 description: 状态(enabled/disabled)
 *     responses:
 *       200:
 *         description: 批量更新货位状态成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *                 data:
 *                   type: object
 *                   properties:
 *                     updated:
 *                       type: integer
 *       400:
 *         description: 请求参数错误
 *       500:
 *         description: 服务器错误
 */
router.put('/status/batch', LocationController.updateLocationStatusBatch);

/**
 * @swagger
 * /api/locations/{id}:
 *   delete:
 *     summary: 删除货位
 *     tags: [Locations]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 货位ID
 *     responses:
 *       200:
 *         description: 货位删除成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *       404:
 *         description: 货位未找到
 *       500:
 *         description: 服务器错误
 */
router.delete('/:id', LocationController.deleteLocation);

module.exports = router;